package com;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;



/**
 *
 * @author Jayesh
 */
public class Root {

    public Connection con = null;
    public Statement stmt = null;
    
    public static String dbURL = null;
    public static String dbName = null;
    public static String dbUserName = null;
    public static String dbPwd = null;
    public static String dbDriver = null;
   
     public void initConnection()
            throws Exception {
        String url = null;
        try {
            if (this.con != null) {
                if (this.stmt == null) {
                    this.stmt = this.con.createStatement();
                }
                return;
            }
        } catch (SQLException ex) {
            System.out.println("SQLException: " + ex.getMessage());
            throw ex;
        }
        try {            
            url = dbURL + dbName;

            Class.forName(dbDriver);
        } catch (ClassNotFoundException e) {
            System.out.println("ClassNotFoundException: " + e.getMessage());
            throw e;
        }
        try {
            this.con = DriverManager.getConnection(url, dbUserName, dbPwd);
            this.stmt = this.con.createStatement();
        } catch (SQLException ex) {
            System.out.println("SQLException: " + ex.getMessage());
            throw ex;
        }
    }
    
    public void closeConnection() {
        try {
            this.stmt.close();
            this.con.close();
            this.con = null;
            this.stmt = null;
        } catch (Exception ex) {
            this.con = null;
            this.stmt = null;
            //System.out.println("Exception: " + ex.getMessage());
            //throw ex;
        }
    }    
    
    public static void Log(String msg) {
        System.out.println(msg);
    }
}
